#ifndef ZMODEM_GLOBAL_H
#define ZMODEM_GLOBAL_H

/* zglobal.h - prototypes etcetera for lrzsz

  Copyright (C) until 1998 Chuck Forsberg (OMEN Technology Inc)
  Copyright (C) 1994 Matt Porter
  Copyright (C) 1996, 1997 Uwe Ohse
  Copyright (C) 2018 Michael L. Gran

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2, or (at your option)
  any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  02111-1307, USA.
*/


#include "zreadline.h"
#include "zporting.h"

//#define time_t int

#define OK 0
#define FALSE 0
#define TRUE 1
#define ERROR (-1)

/* Ward Christensen / CP/M parameters - Don't change these! */
#define ENQ     005       // enquiry 字符 (请求通信)
#define CAN     ('X'&037) // 取消传输
#define XOFF    ('s'&037) // 流量控制停止
#define XON     ('q'&037) // 流量控制恢复
#define SOH     1         // 帧起始符
#define STX     2         // 文本起始符
#define EOT     4         // 传输结束
#define ACK     6         // 确认应答
#define NAK     025       // 否定应答
#define CPMEOF  032
#define WANTCRC 0103      /* send C not NAK to get crc not checksum */
#define WANTG   0107      /* Send G not NAK to get nonstop batch xmsn */
#define TIMEOUT (-2)
#define RCDO    (-3)
#define WCEOT   (-10)

#define RETRYMAX 10 // 最大重试次数

#define UNIXFILE 0xF000  /* The S_IFMT file mask bit for stat */

#define DEFBYTL 2000000000L	/* default rx file size */

enum zm_type_enum {
	ZM_ZMODEM
};

struct zm_fileinfo {
  char   *fname;         // 文件名
  int    modtime;        // 文件最后修改时间 (Unix时间戳)
  int    mode;           // 文件权限模式 (Unix权限位)
  size_t bytes_total;    // 文件总字节数
  size_t bytes_sent;     // 已发送字节数
  size_t bytes_received; // 已接收字节数
  size_t bytes_skipped;  // 已跳过字节数 (用于崩溃恢复)
  int    eof_seen;       // EOF标记 (是否已到达文件结尾)
};

#define R_BYTESLEFT(x) ((x)->bytes_total-(x)->bytes_received)

extern const char *program_name;        /* the name by which we were called */

/* rbsb.c */
extern int Fromcu;
extern int iofd;

/* rbsb.c */
int io_mode (int fd, int n);
void sendbrk (int fd);


/* zm.c */

#endif
